from parser.kconfig_parser import KconfigParser
from parser.config_model import MenuItem, ConfigItem, ChoiceItem, CommentItem


def print_items(items):
    print(f"Top-level items: {len(items)}")
    for item in items:
        if isinstance(item, MenuItem):
            print(f"Menu: {item.prompt} (id={item.id}) children={len(item.children)}")
            for child in item.children:
                if isinstance(child, ConfigItem):
                    p = child.properties
                    print(f"  Config: {child.name} id={child.id} type={p.type} prompt={p.prompt} default={getattr(p.default, 'value', None)}")
                elif isinstance(child, MenuItem):
                    print(f"  Submenu: {child.prompt} (id={child.id}) children={len(child.children)}")
                elif isinstance(child, ChoiceItem):
                    print(f"  Choice: prompt={child.prompt} id={child.id} children={len(child.children)}")
                elif isinstance(child, CommentItem):
                    print(f"  Comment: text={child.text} id={child.id}")
                else:
                    print(f"  Other: {type(child).__name__} id={getattr(child,'id','?')}")
        else:
            print(f"Other top-level: {type(item).__name__} id={getattr(item,'id','?')}")


def main():
    import os
    base = os.path.dirname(os.path.abspath(__file__))
    kconf_path = os.path.join(base, 'examples', 'Kconfig')
    parser = KconfigParser()
    items = parser.parse_file(kconf_path)
    print_items(items)

if __name__ == '__main__':
    main()